import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

//重复点击同一页面路由报错
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}
const routes = [
  {
    path: '/',
    name: '',
    component: ()=>import("../views/login.vue")
  },
  {
    path: '/login',
    name: 'login',
    component: ()=>import("../views/login.vue")
  },
  {
    path: '/home',
    name: 'home',
    component: ()=>import("../views/home.vue"),
    redirect:'admin',
    children:[
      {
        path: '/admin',
        name: 'admin',
        component: ()=>import("../views/admin"),
      },
      {
        path: '/order',
        name: 'order',
        component: ()=>import("../views/order"),
      },
      {
        path: '/category',
        name: 'category',
        component: ()=>import("../views/category"),
      },
      {
        path: '/goods',
        name: 'goods',
        component: ()=>import("../views/goods")
      },
      {
        path: '/adminEdit',
        name: 'adminEdit',
        component: ()=>import("../views/adminEdit"),
      },
      {
        path: '/goodsEdit',
        name: 'goodsEdit',
        component: ()=>import("../views/goodsEdit"),
      },
      {
        path: '/categoryEdit',
        name: 'categoryEdit',
        component: ()=>import("../views/categoryEdit"),
      },
      {
        path: '/top',
        name: 'top',
        component: ()=>import("../views/top"),
      },
    ]
  },
  {
    path: '/order',
    name: 'order',
    component:()=>import("../views/order")
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    // component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue')
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router
